/*
 * ThreadMain.h
 *
 *  Created on: 2017年5月28日
 *      Author: orange
 */

#ifndef THREADMAIN_H_
#define THREADMAIN_H_


#include <pthread.h>
#include <semaphore.h>
#include <string>

#include "../public/concurrentqueue.h"
#include "../public/Plugin.h"

class OnCommandJuzEvent;

extern "C"
{
	Plugin *loadSoPlugin();
}


typedef void* (*JuzTask)(void*);

struct Juz_Task_Ve
{
	JuzTask mTask;
	void *Args;
	string msg;
};

class ThreadMain: public Plugin {
public:
	ThreadMain();
	virtual ~ThreadMain();

	static ThreadMain *getInstance();

	void CheckThread(int count = ThreadMain::nCounter);

    void eventListen(JuzEvent *event); //监听的事件 回调!
    void bindFinsh();

    void access();//访问
    void quit();//退

    void StartThread(int num);
    static void* TaskPro(void *);

    void OnEnable();
    void OnDisable();

    void OnCommand(OnCommandJuzEvent *ev);

public:
    static void Log(string msg,int nPriority = 3);

    static  int nMaxCount;//最大线程数
    static  int nMinCount;//最小线程数
    static  int nCounter;//计数器

    int nCurrentCount;//当前线程数
    int nCurrentWorkCOunt;//当前工作线程数

    pthread_mutex_t *mMutex;

    moodycamel::ConcurrentQueue<Juz_Task_Ve>  TaskQueue;
    sem_t *bin_sem;
public:
    static ThreadMain* mThreadMain;
};


#endif /* THREADMAIN_H_ */
